package com.ithrima.activiti.day04;


import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.Map;

/**
 *
 *   流程变量测试
 */
public class VariableTest {

    // 完成任务   zhangsan  lisi  判断请假天数  wangwu  zhaoliu
    public static void main(String[] args) {
        //1. 得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2. TaskService
        TaskService taskService = processEngine.getTaskService();
        //3. 查询任务
        Task task = taskService.createTaskQuery().processDefinitionKey("holiday").taskAssignee("zhaoliu").singleResult();
        //4. 判断当前是否有任务
        if (task != null) {
            taskService.complete(task.getId());
            System.out.println("任务执行完毕");
        }

    }

    // 启动流程实例，设置流程变量
    //act_ru_variable  act_ge_bytearray 存变量的表
//    public static void main(String[] args) {
//        //1. 得到ProcessEngine对象
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //2. 得到RunTimeService
//        RuntimeService runtimeService = processEngine.getRuntimeService();
//        //3. 流程定义key的问题
//        Map<String, Object> map = new HashMap<>();
//        Holiday holiday = new Holiday();
//        holiday.setNum(5f);
//        map.put("holiday",holiday);
//        //4. 启动流程实例 设置流程变量的值
//        ProcessInstance holiday1 = runtimeService.startProcessInstanceByKey("holiday", map);
//
//        //5. 输出实例信息
//        System.out.println(holiday1.getName());
//        System.out.println(holiday1.getProcessDefinitionId());
//
//    }
    // 请假流程部署
//    public static void main(String[] args) {
//        //1. 得到ProcessEngine对象
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //2. 得到RepositoryService对象
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        //3 部署
//        Deployment deploy = repositoryService.createDeployment()
//                .addClasspathResource("diagram/holiday.bpmn")
//                .addClasspathResource("diagram/holiday.png")
//                .name("测试变量123")
//                .deploy();
//
//        System.out.println(deploy.getId());
//        System.out.println(deploy.getName());
//
//    }

}
